<?php
require_once('libs/BomCommon.php');

function doHellow($input) {	
	$log = new Logger();
	$log->log("BOMBERMAN TEST");
	
    return "Test - เทสข้อมูล ".$input;
}
function getSysDateTime($private_key){
	$log = new Logger();
	$log->log("==saveUserData(private_key=".$private_key.", userid=".$userid.", systolic=".$systolic.", diastolic=".$diastolic.", pulse=".$pulse.")==");
	$sys_date = "1/1/1900";
	$sys_time = "00:00";
	if( (BomCommon::checkPrivateKey($private_key)) ){
		$sys_date = date("j/n/Y");
		$sys_time = date("G:i");
	}
	$sysDateTime = array('SysDate' => $sys_date, 'SysTime' => $sys_time);
	$log->log("sysDateTime=".print_r($sysDateTime, true));
	return $sysDateTime;
}
function getDataWithUserEmail($private_key, $datefrom, $dateto, $arrUserEmail){
	$log = new Logger();
	$arrResult = array();
	$log->log("getDataWithUserEmail(private_key=".$private_key.", datefrom=".$datefrom.", dateto=".$dateto.", arrUserEmail=".print_r($arrUserEmail, true).")");

	if( (BomCommon::checkPrivateKey($private_key)) && count($arrUserEmail)>0 ){
		$log->log("begin do getDataWithUserEmail()");

		$datefrom = trim($datefrom);
		$dateto = trim($dateto);
		$useremails = "";
		for($u=0; $u<count($arrUserEmail); $u++){
			if($u==0) $useremails .= "'".$arrUserEmail[$u]['UserEmail']."'";
			else $useremails .= ",'".$arrUserEmail[$u]['UserEmail']."'";
		}

		$link = BomCommon::openDBConnection();
		$strSQL = "select date_format(ur.record_date, '%e/%c/%Y') as record_datex, u.user_email, u.user_fname, u.user_lname, sum(ur.walk_step_count) as step_count
					from cu_walk_users wu
					join clum_users u on(u.user_email=wu.walk_user_email)
					join cu_walk_user_records ur on(wu.walk_user_id = ur.walk_user_id)
					where wu.walk_user_email in ('pum_u@hotmail.com')
					and ur.record_date between str_to_date('".$datefrom."', '%e/%c/%Y') and str_to_date('".$dateto."', '%e/%c/%Y')
					group by record_date
					order by record_date desc";
		$data = BomCommon::mysql_ToArray(BomCommon::excuteDB($link, $strSQL));
		for($i=0; $i<count($data); $i++){
			array_push($arrUser, array(
				'UserId' => $data[$i]['id'],
				'UserFName' => $data[$i]['user_fname'],
				'UserLName' => $data[$i]['user_lname'],
				'UserEmail' => $data[$i]['user_email'],
				'StepDtm' => $data[$i]['record_datex'],
				'StepCount' => $data[$i]['step_count']
				)
			);
		}
	}
	$log->log("size of data->".count($arrResult));
	$log->log("end getDataWithUserEmail()");
	return $arrResult;
}
?>